﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace dzs.Web.tenderExpert
{
    public partial class AddOrUpTenderFirm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    string strid = Request.Params["id"];
                    int tenderFirmId = (Convert.ToInt32(strid));
                    ShowInfo(tenderFirmId);
                }
            }
            
        }
        private void ShowInfo(int tenderFirmId)
        {
            Maticsoft.BLL.tenderFirm bll = new Maticsoft.BLL.tenderFirm();
            Maticsoft.Model.tenderFirm model = bll.GetModel(tenderFirmId);
            this.lbltenderFirmId.Text = model.tenderFirmId.ToString();
            this.txttenderFirmName.Text = model.tenderFirmName;
            this.txtcontactName.Text = model.contactName;
            this.txtphone.Text = model.phone;
            this.txtfax.Text = model.fax;
            this.txte_mail.Text = model.e_mail;
            this.txtqualification.Text = model.qualification;
            this.txtmaterialLevel.Text = model.materialLevel;

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";
            if (this.txttenderFirmName.Text.Trim().Length == 0)
            {
                strErr += "tenderFirmName不能为空！\\n";
            }
            if (this.txtcontactName.Text.Trim().Length == 0)
            {
                strErr += "contactName不能为空！\\n";
            }
            if (strErr != "")
            {
                Maticsoft.Common.MessageBox.Show(this, strErr);
                return;
            }
            string tenderFirmName = this.txttenderFirmName.Text;
            string contactName = this.txtcontactName.Text;
            string phone = this.txtphone.Text;
            string fax = this.txtfax.Text;
            string e_mail = this.txte_mail.Text;
            string qualification = this.txtqualification.Text;
            string materialLevel = this.txtmaterialLevel.Text;

            Maticsoft.Model.tenderFirm model = new Maticsoft.Model.tenderFirm();
            model.tenderFirmName = tenderFirmName;
            model.contactName = contactName;
            model.phone = phone;
            model.fax = fax;
            model.e_mail = e_mail;
            model.qualification = qualification;
            model.materialLevel = materialLevel;

            Maticsoft.BLL.tenderFirm bll = new Maticsoft.BLL.tenderFirm();


            if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
            {
                model.tenderFirmId = int.Parse(this.lbltenderFirmId.Text);
 
                if (bll.Update(model))
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "ListTenderFirm.aspx");
                }
                else
                {
                    Maticsoft.Common.MessageBox.Show(this, "保存失败！");
                }
            }
            else
            {
                if (bll.Add(model) > 0)
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "ListTenderFirm.aspx");
                }
                else
                {
                    Maticsoft.Common.MessageBox.Show(this, "保存失败！");
                }
            }

          
                       
        }
    }
}